<?php $this->headScript()->appendFile($this->JS_PATH . 'loan.js'); ?>
<?php $this->headScript()->appendFile($this->JS_PATH . 'bootstrap.datepicker.js'); ?>

<div id="loan-listing"></div>
<?php echo $this->flashmessages(); ?>
<?php if (count($this->errorMessage) > 0): ?>
    <div class="alert alert-error">
        <?php foreach ($this->errorMessage as $erroValue): ?>
            <div class="text-left">
                <i class="icon-remove-sign"></i>
                <?php echo $erroValue; ?>
            </div>

        <?php endforeach; ?>
    </div>
<?php endif; ?>
<div id="pad-wrapper">
    <div class="row pagelist-header">
        <h3>Loan Listing</h3>
    </div>
    <div class="table-products">
        <form action="" method="post" id="loanlistingfrm">

            <div class="row-fluid ">
                <div class="pull-right">

                    <div class="ui-select" >
                        <select name="searchtype" id="searchtype">
                            <option value="">Select Type</option>
                            <option value="ln_name" <?php if ($this->searchtype == 'ln_name'): ?> selected <?php endif; ?> >Loan Name</option>
                            <option value="cus_name" <?php if ($this->searchtype == 'cus_name'): ?> selected <?php endif; ?> >Customer Name</option>
                            <option value="ag_name" <?php if ($this->searchtype == 'ag_name'): ?> selected <?php endif; ?> >Agent Name</option>
                            <option value="ln_startdate" <?php if ($this->searchtype == 'ln_startdate'): ?> selected <?php endif; ?>>Start Date</option>
                            <option value="ln_enddate" <?php if ($this->searchtype == 'ln_enddate'): ?> selected <?php endif; ?>>End Date</option>
                        </select>
                    </div>
                    <span id="loan_text_field" class="display-none">
                        <input type="text" class="search" name="searchtext_loan" id="searchtext_loan"  value="<?php echo $this->searchtext ?>" placeholder="Search" >
                    </span>

                    <span id="agent_text_field" class="display-none">
                        <input type="text" class="search" name="searchtext_agent" id="searchtext_agent"  value="<?php echo $this->searchtext ?>" placeholder="Search" >
                    </span>
                    

                    <span id="customer_text_field" class="display-none">
                        <input type="text" class="search" name="searchtext_customer" id="searchtext_customer"  value="<?php echo $this->searchtext ?>" placeholder="Search" >
                    </span>


                    <span id="start_date_range" class="display-none">
                        &nbsp; <input type="text" class="search_date datepicker" name="searchtext_startfromdate" id="searchtext_startfromdate" value="<?php echo $this->searchtext_fromdate ?>" placeholder="From"  >
                        &nbsp;<input type="text" class="search_date datepicker" name="searchtext_starttodate" id="searchtext_starttodate" value="<?php echo $this->searchtext_todate ?>" placeholder="To" >
                    </span>


                    <span id="end_date_range" class="display-none">
                       &nbsp; <input type="text" class="search_date datepicker" name="searchtext_endfromdate" id="searchtext_endfromdate" value="<?php echo $this->searchtext_fromdate ?>" placeholder="From"  >
                       &nbsp;<input type="text" class="search_date datepicker" name="searchtext_endtodate" id="searchtext_endtodate" value="<?php echo $this->searchtext_todate ?>" placeholder="To" >
                    </span>

                    <input type="submit" value="Search" name="searchbutton"  id="searchbutton" class="btn-flat new-product"/>      
                    <a class="btn-flat new-product"
                       href="<?php echo $this->url(array('module' => 'default', 'controller' => 'loan', 'action' => 'form'), null, TRUE); ?>"
                       >+ Add Loan</a>                        
                </div>
            </div>

            <div class="row">
                <?php if (count($this->loansData) > 0): ?> 
                    <div class="delete_All">    
                        <input type="submit" accesskey="s" value="Delete All" name="multiaction"  id="multiaction" class="btn-flat danger"/>      
                    <?php else: ?>
                        &nbsp;
                <?php endif; ?>
                </div>
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th class="col-md-3 ">
                                <input id="selectall" type="checkbox"/>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                Name
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3 ">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ag_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                Agent Name
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ag_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            
                            <th class="col-md-3 ">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'cus_name', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                Customer Name
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'cus_name', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>

                            <th class="col-md-3 ">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_startdate', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                Start Date
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_startdate', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>

                            <th class="col-md-3 ">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_enddate', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                End Date
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_enddate', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                            </th>
                            <th class="col-md-3">
                                <span class="line"></span>
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_status', 'sort' => 'asc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_asc.png"  alt="Ascending" title="Ascending" class="sort_asc" />
                                </a>
                                Status
                                <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'list', 'field' => 'ln_status', 'sort' => 'desc'), 'default', false); ?>">
                                    <img src="<?php echo $this->IMAGE_PATH; ?>datatables/sort_desc.png"  alt="Descending" title="Descending" class="sort_desc"  />
                                </a>
                                <span class="cls_action"> Action</span>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (count($this->loansData) > 0): ?>
                            <?php $counter = 0; ?>
                            <?php foreach ($this->loansData as $key => $value) : ?>
                                <!-- row -->
                                <tr <?php if ($counter == 0): ?>class="first"<?php endif; ?>>
                                    <td>
                                        <input type="checkbox" class="content-checkbox" name="multicheck[]" value="<?php echo $value["ln_id"]; ?>"/>
                                        <a href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'form', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                            <?php echo ucfirst($value['ln_name']); ?>
                                        </a>
                                    </td>
                                    <td >
                                        <?php echo $value['ag_name']; ?>
                                    </td>
                                    
                                    <td class="">
                                        <?php echo $value['cus_name']; ?>
                                    </td>

                                    <td class="">
                                        <?php echo $value['ln_startdate']; ?>
                                    </td>

                                    <td class="">
                                        <?php echo $value['ln_enddate']; ?>
                                    </td>
                                    <td>
                                        <?php if ($value['ln_status'] == 1): ?>
                                            <span class="label label-success">Active</span>
                                        <?php else:
                                            ?>
                                            <span class="label label-info">InActive</span>
                                        <?php
                                        endif;
                                        ?>
                                        <a class="label label-add" title="Add Installment" href="<?php echo $this->url(array('controller' => 'installment', 'action' => 'form', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                            Add Installment
                                        </a>
                                        <a class="label label-add" href="<?php echo $this->url(array('module' => 'default', 'controller' => 'loan', 'action' => 'getcsv', 'ln_id' => $value["ln_id"]), null, TRUE); ?>">
                                            Download CSV
                                        </a>
                                        <ul class="actions">
                                            <li class="display-none">
                                                <a class="view_anchr" title="Download Document" href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'download', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                                    <i class="icon-download-alt"></i>
                                                </a>
                                            </li>
                                            <li>
                                                <a title="Edit" href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'form', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                                    <i class="table-edit"></i>
                                                </a>
                                            </li>
                                            <li >
                                                <a title="View" class="view_anchr" href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'view', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                                    <i class="icon-eye-open"></i>
                                                </a>
                                            </li>
                                            <li class="last">
                                                <a title="Delete" href="<?php echo $this->url(array('controller' => 'loan', 'action' => 'delete', 'ln_id' => $value["ln_id"]), null, true); ?>">
                                                    <i class="table-delete"></i>
                                                </a>
                                            </li>

                                        </ul>
                                    </td>
                                </tr>
                                <?php $counter++; ?>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <tr class="row2" >
                                <td>&nbsp;</td>
                                <td colspan="8"> No Record Found</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            <?php
            if (count($this->loansData) > 0):
                echo $this->paginator->displayPages();
            endif;
            ?>

        </form>
    </div>
</div>